package com.example.sys.speciality.controller;

import com.example.core.controller.BaseController;
import com.example.core.utils.Result;
import com.example.core.utils.UserUtils;
import com.example.sys.speciality.po.SysSpeciality;
import com.example.sys.speciality.service.SysSpecialityService;
import com.example.sys.speciality.vo.SysSpecialityVo;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RequestMapping("sysSpeciality")
@RestController
public class SysSpecialityController extends BaseController<SysSpecialityService, SysSpecialityVo> {

    /****
     * 获取指定用户的专业信息
     * @return
     */
    @GetMapping("getSpeciality")
    public Result getSpeciality() {
        try {
            List<SysSpeciality> sysSpecialities = this.getService().getSpecialityByUserId(UserUtils.getUserId());
            return Result.success(new SysSpecialityVo(sysSpecialities));
        } catch (Exception e) {
            return Result.error(e.getMessage());
        }
    }

    /***
     *
     * 这个方法是专门用于微信平台用户设置专业信息
     * @param sysSpecialities
     * @return
     */
    @RequestMapping("setSpecialityByMp")
    public Result setSpecialityByMp(@RequestBody List<SysSpeciality> sysSpecialities) {
        try {
            this.getService().setSpecialityByMP(sysSpecialities);
            return Result.success();
        } catch (Exception e) {
            e.printStackTrace();
            return Result.error(e.getMessage());
        }
    }

    /***
     *
     * 分配设置专家专业信息
     * @param sysSpecialityVo
     * @return
     */
    @RequestMapping("setSpeciality")
    public Result setSpeciality(@RequestBody SysSpecialityVo sysSpecialityVo) {
        try {
            this.getService().setSpeciality(sysSpecialityVo);
            return Result.success();
        } catch (Exception e) {
            e.printStackTrace();
            return Result.error(e.getMessage());
        }
    }

    @RequestMapping("delSpeciality")
    public Result delSpeciality(String id) {
        try {
            this.getService().delete(id);
            return Result.success();
        } catch (Exception e) {
            e.printStackTrace();
            return Result.error(e.getMessage());
        }
    }
}
